﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Rugicon
{
    /// <summary>
    /// Exposes the most common emoticon tasks.
    /// </summary>
    public static class Emoticons
    {
        /// <summary>
        /// The Live Messenger service. By now, it is static and fixed in code.
        /// </summary>
        private static LiveEmoticonService LiveEmoticons = new LiveEmoticonService();

        /// <summary>
        /// The file system based service. By now, it is static and fixed in code.
        /// </summary>
        private static FileEmoticonService FileEmoticons = new FileEmoticonService();

        /// <summary>
        /// Raised when new emoticons are available by the different sources.
        /// </summary>
        public static event EventHandler<EventArgs> EmoticonsChanged;

        /// <summary>
        /// Sets up the emoticon services.
        /// </summary>
        static Emoticons()
        {
            // Subscribe to the emoticons changed event to bubble them up.
            LiveEmoticons.EmoticonsChanged += (s, e) => { EmoticonsChanged(s, e); };         
            FileEmoticons.EmoticonsChanged += (s, e) => { EmoticonsChanged(s, e); };
        }

        /// <summary>
        /// Gets all emoticons, from all emoticon sets, from all providers.
        /// </summary>
        /// <returns>Emoticons!</returns>
        public static IEnumerable<Emoticon> GetAllEmoticons()
        {
            // By now, only there are only two services.
            var liveSets = LiveEmoticons.GetEmoticonSets();
            var fileSets = FileEmoticons.GetEmoticonSets();

            var allSets = liveSets.Union(fileSets);
            var allEmoticons = new List<Emoticon>();

            foreach (var set in allSets)
                allEmoticons.AddRange(set.Emoticons);

            return allEmoticons;
        }

        /// <summary>
        /// Gets all emoticon sets from all providers.
        /// </summary>
        /// <returns>Emoticon sets!</returns>
        public static IEnumerable<EmoticonSet> GetAllEmoticonSets()
        {
            // By now, only there are only two services.
            var liveSets = LiveEmoticons.GetEmoticonSets();
            var fileSets = FileEmoticons.GetEmoticonSets();

            return liveSets.Union(fileSets);
        }
    }
}
